package net.huashitong.oversee.service;

import com.yunpian.sdk.YunpianClient;
import com.yunpian.sdk.model.Result;
import com.yunpian.sdk.model.SmsSingleSend;
import net.huashitong.oversee.entity.SupervisionTask;
import net.huashitong.utils.UtilsTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.Map;

@Service
public class FeedBackLeaderService {
    private static Logger log  = LoggerFactory.getLogger(FeedBackLeaderService.class);

    public void feedLeader(SupervisionTask items,String telphone)
    {
        String msg=   "【重大项目节点管理】您好!督查任务:"+items.getTaskName()+",任务结果:未完成,该督查组"+"无"+"督查催办记录.督查小组为:"+items.getGroupType() + ",责任单位为:"+items.getResDept()+",请及时处理。系统地址：https://www.fzzhengxinyun.com ，帐号为个人手机号，初始密码123456";
        YunpianClient clnt = new YunpianClient(UtilsTools.msgapiKey).init();
        //修改账户信息API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE ,telphone); //攻坚办短信
        param.put(YunpianClient.TEXT, msg);
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        log.info("----------------"+r.getCode()+"============");
        System.out.println(r.getMsg());
        log.info("------------"+r.getMsg()+"----------");
        clnt.close();
    }
    //发短信给督查组和责任单位
    public int  sendMsgToDuchaAndDept(String projectName,String sysid,String taskName,String phone)
    {
        String msg ="【重大项目节点管理】您好,项目<"+projectName+">超期未完成,系统已生成督查任务,任务单号为:"+sysid+",督查任务名为:<"+taskName+">,请及时跟进以完成该督查任务,可登录系统添加督查任务跟踪情况！系统地址：https://www.fzzhengxinyun.com ，帐号为个人手机号，初始密码123456";
        YunpianClient clnt = new YunpianClient(UtilsTools.msgapiKey).init();
        //修改账户信息API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE,phone); //攻坚办短信
        param.put(YunpianClient.TEXT, msg);
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        log.info("----------------"+r.getCode()+"============");
        System.out.println(r.getMsg());
        log.info("------------"+r.getMsg()+"----------");
        clnt.close();
        return r.getCode();

    }
    //协调事项申报发短信
    public int QuesttionSendMsg(String msg,String phone)
    {
        YunpianClient clnt = new YunpianClient(UtilsTools.msgapiKey).init();
        //修改账户信息API
        Map<String, String> param = clnt.newParam(2);
        param.put(YunpianClient.MOBILE,phone); //攻坚办短信
        param.put(YunpianClient.TEXT, msg);
        Result<SmsSingleSend> r = clnt.sms().single_send(param);
        log.info("----------------"+r.getCode()+"============");
      //  System.out.println(r.getMsg());
       log.info("------------"+r.getMsg()+"----------");
        clnt.close();
        return r.getCode();
    }

}
